package com.varian.boot.config;

import com.varian.boot.filter.ServletLogFilter;
import com.varian.boot.jackson.VarianJacksonModel;
import com.varian.boot.listener.ApplicationStartedListener;
import com.varian.boot.listener.DefaultApplicationStarted;
import com.varian.boot.properties.VarianLoggingProperties;
import com.varian.misc.ApplicationStartedCustomizer;
import com.varian.tool.log.TraceIdFilter;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;

import java.util.List;

/**
 * @author ben
 * @since 2024/6/22
 */
@AutoConfiguration
@EnableConfigurationProperties({VarianLoggingProperties.class})
public class BootAutoConfig {

    @Bean
    public ServletLogFilter servletLogFilter(VarianLoggingProperties properties) {
        return new ServletLogFilter(properties);
    }

    @Bean
    public TraceIdFilter traceIdFilter() {
        return new TraceIdFilter();
    }

    @Bean
    public VarianJacksonModel varianJacksonModel() {
        return new VarianJacksonModel();
    }

    @Bean
    public ApplicationStartedCustomizer defaultApplicationStarted() {
        return new DefaultApplicationStarted();
    }

    @Bean
    public ApplicationStartedListener applicationStartedListener(List<ApplicationStartedCustomizer> customizers) {
        return new ApplicationStartedListener(customizers);
    }

    @Bean
    public LocalValidatorFactoryBean localValidatorFactoryBean() {
        return new LocalValidatorFactoryBean();
    }
}
